/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#include "TextCollection.hpp"
#include "Settings.hpp"

#include <sstream>

namespace hny 
{
	TextCollection::TextCollection()
	{
		mFont1 = new hgeFont("Content/font1.fnt");
		mFont2 = new hgeFont("Content/font2.fnt");

		HighestComboText = "Highest combo:";
		HighestComboValue = 0;

		ScoreText = "Score:";
		ScoreValue = 0;

		ActiveRocketsText = "Active rockets:";
		ActiveRocketsValue = 0;

		TimeText = "Time:";
		TimeValue = 0.0f;

		MultiplierText = "Multiplier:";
		MultiplierValue = 0;

		NoRocketsText = "Rockets:";
		NoRocketsValue = 0;
	}

	TextCollection::~TextCollection()
	{
		//delete mFont1;
		//delete mFont2;
	}

	void TextCollection::Draw()
	{
		/* 
		   TODO: Fix performance!
		*/

		const float rStartX = 890;
		const float rStartY = 200;

		const float lStartX = 20;
		const float lStartY = 200;

		const float rowHeight = 20;

		float rrow = 0;
		float lrow = 0;

		hgeColor color(1.0f, 1.0f, 1.0f, 1.0f);

		//////////////////////////////////////////////////////////////////////////
		// RIGHT SIDE

		// Score
		std::stringstream ss;
		ss << ScoreValue;

		mFont1->SetScale(0.6f);
		mFont1->SetColor(color.GetHWColor());
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, ScoreText.c_str());
		rrow+= rowHeight;
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, ss.str().c_str());

		rrow+= rowHeight;

		// Combos
		std::stringstream ss2;
		ss2 << HighestComboValue;

		mFont1->SetScale(0.6f);
		mFont1->SetColor(color.GetHWColor());
		rrow+= rowHeight;
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, HighestComboText.c_str());
		rrow+= rowHeight;
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, ss2.str().c_str());

		rrow += rowHeight;

		// Multiplier
		std::stringstream ssm;
		ssm << MultiplierValue << " %";

		hgeColor multColor(1.0f, 1.0f, 1.0f, 1.0f);
		if(MultiplierValue > Settings::GetInstance()->MultiplierHighlight1)
			multColor = hgeColor(0.0f, 0.5f, 1.0f, 1.0f);
		if(MultiplierValue > Settings::GetInstance()->MultiplierHighlight2)
			multColor = hgeColor(0.0f, 1.0f, 0.0f, 1.0f);

		
		mFont1->SetScale(0.6f);
		mFont1->SetColor(color.GetHWColor());
		rrow+= rowHeight;
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, MultiplierText.c_str());
		rrow+= rowHeight;
		mFont1->SetColor(multColor.GetHWColor());
		mFont1->Render(rStartX, rStartY + rrow, HGETEXT_LEFT, ssm.str().c_str());

		rrow += rowHeight;

		//////////////////////////////////////////////////////////////////////////
		// LEFT SIDE

		std::stringstream ss3;
		ss3 << ActiveRocketsValue;

		// Active rockets
		mFont1->SetScale(0.6f);
		mFont1->SetColor(color.GetHWColor());
		mFont1->Render(lStartX, lStartY + lrow, HGETEXT_LEFT, ActiveRocketsText.c_str());
		lrow+= rowHeight;
		mFont1->Render(lStartX, lStartY + lrow, HGETEXT_LEFT, ss3.str().c_str());


		lrow += rowHeight;
		lrow += rowHeight;

		// Time left
	
		std::stringstream ss4;
		ss4 << TimeValue;

		hgeColor timeColor(1.0f, 1.0f, 1.0f, 1.0f);
		if(TimeValue < Settings::GetInstance()->TimeWarning1)
			timeColor = hgeColor(1.0f, 1.0f, 0.0f, 1.0f);
		if(TimeValue < Settings::GetInstance()->TimeWarning2)
			timeColor = hgeColor(1.0f, 0.0f, 0.0f, 1.0f);
		
		mFont1->SetScale(0.6f);
		mFont1->SetColor(color.GetHWColor());
		mFont1->Render(lStartX, lStartY + lrow, HGETEXT_LEFT, TimeText.c_str());
		lrow+= rowHeight;
		mFont1->SetColor(timeColor.GetHWColor());
		mFont1->Render(lStartX, lStartY + lrow, HGETEXT_LEFT, ss4.str().c_str());

	}
}